import java.util.HashSet;
import java.util.Set;

/**
 * @program: LeetCode
 * @description: LeetCode : 3. 无重复字符的最长子串
 * @author: WXY
 * @create: 2022-12-23 15:43
 * @Version 1.0
 **/

public class Num003_lengthOfLongestSubstring {
    public static int lengthOfLongestSubstring(String s) {
        int len = 0;
        int l = 0;
        Set<Character> set = new HashSet<>();
        for (int r = 0; r < s.length(); r++) {
            char c = s.charAt(r);
            while (set.contains(c)) {
                set.remove(s.charAt(l++));
            }
            set.add(c);
            len = Math.max(len, r - l + 1);
        }
        return len;
    }

    public static void main(String[] args) {
        String str = "abcbcgdhkabd";
        int i = lengthOfLongestSubstring(str);
        System.out.println(i);
    }
}
